package com.dys.config;

import com.dys.listenner.MyHttpSessionListener;
import com.dys.servlet.MyServlet;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: 疾风
 * @ClassName: MyMvcConfig
 * @Description: SpringMVC拓展
 * @CreateDate: 2024/11/21
 * @Version: v1.0.0
 */
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    @Bean
    public ServletListenerRegistrationBean listenerRegistrationBean() {
        ServletListenerRegistrationBean srb = new ServletListenerRegistrationBean();
        srb.setListener(new MyHttpSessionListener());
        System.out.println("MyHttpSessionListener");
        return srb;
    }

    /**
     * 统计在线人数,需要注释这部分内容
     * @return
     */
    @Bean
    public ServletRegistrationBean<MyServlet> getServletRegistrationBean(){
        ServletRegistrationBean<MyServlet> bean = new ServletRegistrationBean<>(new MyServlet());
        bean.setLoadOnStartup(1);
        return bean;
    }
}
